<template>
  <card ref="Card">
    <div slot="header">
      <el-button class="float-right" type="primary" icon="el-icon-plus" @click="add">新增</el-button>
    </div>
    <el-table :data="formData">
      <el-table-column prop="beginUserName" label="起始网点"/>
      <el-table-column prop="endUserName" label="到达网点"/>
      <el-table-column label="物流时间(h)">
        <template slot-scope="scope">
          <el-tag type="primary">{{scope.row.time}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" width="150">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" @click.stop="edit(scope.row)"></el-button>
          <delete-button :ref="scope.row.id" :id="scope.row.id" @start="delData"/>
        </template>
      </el-table-column>
    </el-table>
    <pagination ref="Pagination" @update="getData"/>
    <add ref="Add" @update="getData"></add>
    <edit ref="Edit" @update="getData"></edit>
  </card>
</template>

<script>
  import {listPathPlanningApi, delPathPlanningApi} from '@/api/site/route';
  import Add from './add';
  import Edit from './edit';
  import {objectEvaluate} from "@/utils/common";

  export default {
    name: "LogisticsRoute",
    components: {Add, Edit},
    data() {
      return {
        formData: []
      }
    },
    mounted() {
      this.getData()
    },
    methods: {
      getData() {
        let pagination = this.$refs.Pagination;
        let param = {
          current: pagination.current,
          size: pagination.size
        };
        this.$refs.Card.start();
        listPathPlanningApi(param).then(result => {
          // let response =
          this.formData = result.resultParam.pathPlanningList;
          // pagination.total = response.total;
          this.$refs.Card.stop();
        })
      },
      add() {
        this.$refs.Add.visible = true
      },
      edit(obj) {
        let _this = this.$refs.Edit;
        objectEvaluate(_this.form, obj);
        _this.visible = true
      },
      delData(id) {
        delPathPlanningApi({id: id})
          .then(() => {
            this.getData();
            this.$refs[id].close()
          })
          .catch(() => {
            this.$refs[id].stop();
          })
      }
    }
  }
</script>
